package com.lhkj.ct.meta.modules.patient.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.mybatis.core.metadata.SqlOrder;
import com.lhkj.ct.meta.modules.patient.mapper.mapper.TblUnitTaskMapper;
import com.lhkj.ct.meta.modules.patient.model.entity.TblUnitTask;
import com.lhkj.ct.meta.modules.patient.service.service.ITblUnitTaskService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 单位任务 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2023-12-23
 */
@Service
public class TblUnitTaskServiceImpl extends ServiceImpl<TblUnitTaskMapper, TblUnitTask> implements ITblUnitTaskService {

    @Override
    public IPage<TblUnitTask> selectTaskPage(TblUnitTask task, PageQuery pageQuery) {
        LambdaQueryWrapper<TblUnitTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(task.getUnitId()), TblUnitTask::getUnitId, task.getUnitId());
        queryWrapper.eq(null != task.getStatus(), TblUnitTask::getStatus, task.getStatus());
        queryWrapper.like(StringUtils.isNotBlank(task.getTitle()), TblUnitTask::getTitle, task.getTitle());
        if (pageQuery.getBeginTime() != null && pageQuery.getEndTime() != null) {
            queryWrapper.between(TblUnitTask::getReminderDate, pageQuery.getBeginTime(), pageQuery.getEndTime());
        }
        Page<TblUnitTask> page = generatePage(pageQuery, SqlOrder.desc(TblUnitTask::getCreateTime));
        return getBaseMapper().selectPage(page, queryWrapper);
    }
}
